home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / PowerD / powerd / modules.lha / modules / utility / pack.m < prev    next >
Encoding:
Text File  |  2000-08-04  |  5.5 KB  |  129 lines

  1. /*
  2. **    $VER: pack.m 39.3 (10.2.1993)
  3. **    Includes Release 44.1
  4. **
  5. **    Control attributes for Pack/UnpackStructureTags()
  6. **
  7. **    (C) Copyright 1992-1999 Amiga, Inc.
  8. **    All Rights Reserved
  9. */
  10.  
  11. MODULE    'utility/tagitem'
  12.  
  13. /* PackTable definition:
  14.  *
  15.  * The PackTable is a simple array of LONGWORDS that are evaluated by
  16.  * PackStructureTags() and UnpackStructureTags().
  17.  *
  18.  * The table contains compressed information such as the tag offset from
  19.  * the base tag. The tag offset has a limited range so the base tag is
  20.  * defined in the first longword.
  21.  *
  22.  * After the first longword, the fields look as follows:
  23.  *
  24.  *    +--------- 1 = signed, 0 = unsigned (for bits, 1=inverted boolean)
  25.  *    |
  26.  *    |  +------ 00 = Pack/Unpack, 10 = Pack, 01 = Unpack, 11 = special
  27.  *    | / \
  28.  *    | | |  +-- 00 = Byte, 01 = Word, 10 = Long, 11 = Bit
  29.  *    | | | / \
  30.  *    | | | | | /----- For bit operations: 1 = TAG_EXISTS is TRUE
  31.  *    | | | | | |
  32.  *    | | | | | | /-------------------- Tag offset from base tag value
  33.  *    | | | | | | |              \
  34.  *    m n n o o p q q q q q q q q q q r r r s s s s s s s s s s s s s
  35.  *                    \   | |              |
  36.  *    Bit offset (for bit operations) ----/ |              |
  37.  *                          \               |
  38.  *    Offset into data structure -----------------------------------/
  39.  *
  40.  * A -1 longword signifies that the next longword will be a new base tag
  41.  *
  42.  * A 0 longword signifies that it is the end of the pack table.
  43.  *
  44.  * What this implies is that there are only 13-bits of address offset
  45.  * and 10 bits for tag offsets from the base tag.  For most uses this
  46.  * should be enough, but when this is not, either multiple pack tables
  47.  * or a pack table with extra base tags would be able to do the trick.
  48.  * The goal here was to make the tables small and yet flexible enough to
  49.  * handle most cases.
  50.  */
  51. FLAG    PST_SIGNED=31,
  52.         PST_UNPACK=30,        /* Note that these are active low... */
  53.         PST_PACK=29,        /* Note that these are active low... */
  54.         PST_EXISTS=26        /* Tag exists bit true flag hack...  */
  55.  
  56. CONST    PKCTRL_PACKUNPACK=0,
  57.         PKCTRL_PACKONLY=$40000000,
  58.         PKCTRL_UNPACKONLY=$20000000,
  59.         PKCTRL_BYTE=$80000000,
  60.         PKCTRL_WORD=$88000000,
  61.         PKCTRL_LONG=$90000000,
  62.         PKCTRL_UBYTE=0,
  63.         PKCTRL_UWORD=$8000000,
  64.         PKCTRL_ULONG=$10000000,
  65.         PKCTRL_BIT=$18000000,
  66.         PKCTRL_FLIPBIT=$98000000
  67.  
  68. /* Macros used by the next batch of macros below. Normally, you don't use
  69.  * this batch directly. Then again, some folks are wierd
  70.  */
  71. #define PK_BITNUM1(flg)                    (IF (flg)=$01 THEN 0 ELSE IF (flg)=$02 THEN 1 ELSE IF (flg)=$04 THEN 2 ELSE IF (flg)=$08 THEN 3 ELSE IF (flg)=$10 THEN 4 ELSE IF (flg)=$20 THEN 5 ELSE IF (flg)=$40 THEN 6 ELSE 7)
  72. #define PK_BITNUM2(flg)                    (IF (flg)<$100 THEN PK_BITNUM1(flg) ELSE 8+PK_BITNUM1(flg>>8))
  73. #define PK_BITNUM(flg)                    (IF (flg)<$10000 THEN PK_BITNUM2(flg) ELSE 16+PK_BITNUM2(flg>>16))
  74. #define PK_WORDOFFSET(flg)                (IF (flg)<$100 THEN 1 ELSE 0)
  75. #define PK_LONGOFFSET(flg)                (IF (flg)<$100 THEN 3 ELSE IF (flg)<$10000 THEN 2 ELSE IF (flg)<$1000000 THEN 1 ELSE 0)
  76. #define PK_CALCOFFSET(type,field)    (&0::type.field)
  77.  
  78. /* Some handy dandy macros to easily create pack tables
  79.  *
  80.  * Use PACK_STARTTABLE() at the start of a pack table. You pass it the
  81.  * base tag value that will be handled in the following chunk of the pack
  82.  * table.
  83.  *
  84.  * PACK_ENDTABLE() is used to mark the end of a pack table.
  85.  *
  86.  * PACK_NEWOFFSET() lets you change the base tag value used for subsequent
  87.  * entries in the table
  88.  *
  89.  * PACK_ENTRY() lets you define an entry in the pack table. You pass it the
  90.  * base tag value, the tag of interest, the type of the structure to use,
  91.  * the field name in the structure to affect and control bits (combinations of
  92.  * the various PKCTRL_XXX bits)
  93.  *
  94.  * PACK_BYTEBIT() lets you define a bit-control entry in the pack table. You
  95.  * pass it the same data as PACK_ENTRY, plus the flag bit pattern this tag
  96.  * affects. This macro should be used when the field being affected is byte
  97.  * sized.
  98.  *
  99.  * PACK_WORDBIT() lets you define a bit-control entry in the pack table. You
  100.  * pass it the same data as PACK_ENTRY, plus the flag bit pattern this tag
  101.  * affects. This macro should be used when the field being affected is word
  102.  * sized.
  103.  *
  104.  * PACK_LONGBIT() lets you define a bit-control entry in the pack table. You
  105.  * pass it the same data as PACK_ENTRY, plus the flag bit pattern this tag
  106.  * affects. This macro should be used when the field being affected is longword
  107.  * sized.
  108.  *
  109.  * EXAMPLE:
  110.  *
  111.  *    ULONG packTable[] =
  112.  *    {
  113.  *       PACK_STARTTABLE(GA_Dummy),
  114.  *       PACK_ENTRY(GA_Dummy,GA_Left,Gadget,LeftEdge,PKCTRL_WORD|PKCTRL_PACKUNPACK),
  115.  *       PACK_ENTRY(GA_Dummy,GA_Top,Gadget,TopEdge,PKCTRL_WORD|PKCTRL_PACKUNPACK),
  116.  *       PACK_ENTRY(GA_Dummy,GA_Width,Gadget,Width,PKCTRL_UWORD|PKCTRL_PACKUNPACK),
  117.  *       PACK_ENTRY(GA_Dummy,GA_Height,Gadget,Height,PKCTRL_UWORD|PKCTRL_PACKUNPACK),
  118.  *       PACK_WORDBIT(GA_Dummy,GA_RelVerify,Gadget,Activation,PKCTRL_BIT|PKCTRL_PACKUNPACK,GACT_RELVERIFY)
  119.  *       PACK_ENDTABLE
  120.  *    };
  121.  */
  122. #define    PACK_STARTTABLE(tagbase)            (tagbase)
  123. #define    PACK_NEWOFFSET(tagbase)            (-1),(tagbase)
  124. CONST        PACK_ENDTABLE=0
  125. #define    PACK_ENTRY(tagbase,tag,type,field,control)       (control | ((tag-tagbase) << 16) | PK_CACOFFSET(type,field))
  126. #define    PACK_BYTEBIT(tagbase,tag,type,field,control,flags) (control | ((tag-tagbase) << 16) | PK_CACOFFSET(type,field) | (PK_BITNUM(flags) << 13))
  127. #define    PACK_WORDBIT(tagbase,tag,type,field,control,flags) (control | ((tag-tagbase) << 16) | (PK_CACOFFSET(type,field)+PK_WORDOFFSET(flags)) | ((PK_BITNUM(flags)&7) << 13))
  128. #define    PACK_LONGBIT(tagbase,tag,type,field,control,flags) (control | ((tag-tagbase) << 16) | (PK_CACOFFSET(type,field)+PK_LONGOFFSET(flags)) | ((PK_BITNUM(flags)&7) << 13))
  129.